using System;
using System.Data;
using Framework.Library;
using Framework.Library.Components.Commands;
using Framework.Library.Components.Security;
using Framework.Library.Components.Users;
using Framework.Library.Utilities;

namespace Framework.WebControls
{
    class LinkButton_View : System.Web.UI.WebControls.LinkButton
    {
        protected bool pmsRole;
        protected bool pmsRole1;

        private AuthenticatedPage CurrentPage
        {
            get { return (AuthenticatedPage)this.Page; }
        }

        protected UserInfo CurrentUser
        {
            get { return CurrentPage.CurrentUser; }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnInit(e);

            DataTable dt = CommandController.GetButtonRoleForUserByPortalID(CurrentUser.UserID, ConvertUtility.ToInt32(AppEnv.PortalId()));

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows.Count > 1)
                {
                    pmsRole = ConvertUtility.ToBoolean(dt.Rows[0]["Role_View"]);
                    pmsRole1 = ConvertUtility.ToBoolean(dt.Rows[1]["Role_View"]);

                    if (!pmsRole && !pmsRole1)
                    {
                        this.Visible = false;
                    }
                    else
                    {
                        this.Visible = true;
                    }
                }
                else
                {
                    pmsRole = ConvertUtility.ToBoolean(dt.Rows[0]["Role_View"]);
                    if (!pmsRole)
                    {
                        this.Visible = false;
                    }
                    else
                    {
                        this.Visible = true;
                    }
                }
            }
            else
            {
                this.Visible = false;
            }
        }
    }
}
